<template>
  <div>
    <el-form
      :model="form"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
      style="width: 500px; margin: 0 auto; text-align: left"
    >
      <el-form-item label="字典类型名称" prop="TypeName">
        <el-input v-model="form.typeName"></el-input>
      </el-form-item>
      <el-form-item label="排序ID" prop="DicId">
        <el-input v-model="form.dicId"></el-input>
      </el-form-item>
      <el-form-item label="是否启用" prop="State">
        <el-radio-group v-model="form.state">
          <el-radio :label="true">启用</el-radio>
          <el-radio :label="false">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >编辑</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {
  getdictionarysinfoapi,
  updatedictionarysapi,
} from "@/api/sysconfig/Dictionary";
export default {
  data() {
    return {
      form: {
        id: "",
        typeName: "",
        dicId: "",
        state: "",
      },
      rules: {},
    };
  },
  methods: {
    getdictionarys() {
      var stretd = {
        id: this.$route.query.id,
      };
      getdictionarysinfoapi(stretd).then(
        (res) => {
          this.form = {
            id: res.data.data.id,
            typeName: res.data.data.typeName,
            dicId: res.data.data.dicId,
            state: res.data.data.state,
          };
        },
        (err) => {
          console.error(err);
        }
      );
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        updatedictionarysapi(this.form).then(
          (res) => {
            if (res.data.code == 0) {
              this.$message.success("修改成功");
              //跳转到列表页面
              this.$router.push("DictionaryList");
            }
          },
          (err) => {
            console.error(err);
          }
        );
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  created() {
    this.getdictionarys();
  },
};
</script>
<style>
</style>